package com.xiaobaibai.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaobaibai.common.OrderCommon;
import com.xiaobaibai.entity.*;
import com.xiaobaibai.response.ResponseFormat;
import com.xiaobaibai.service.*;
import com.xiaobaibai.units.SecurityUnit;
import com.xiaobaibai.units.ValidList;
import com.xiaobaibai.valid.AddGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@Api(tags = "商品评价接口")
@RequestMapping("/evaluation")
@CrossOrigin
@Slf4j
public class ProductEvaluationController {

    @Autowired
    private IProductEvaluationService productEvaluationService;

    @PostMapping("/do-evaluation")
    @ApiOperation("发表评价")
//    @CacheEvict(value = "evaluation",key = "'getListByProductId-'+#productEvaluation.productId")//已手动消除
    public ResponseFormat addEvaluation2(@RequestBody @Valid
                                                 ValidList<ProductEvaluation> list){
        try {
            productEvaluationService.addEvaluationList(list);
        }catch (Exception e){
            log.error("发表评价错误,第一个orderItem:"+list.get(0).getOrderItemId());
            log.error(e.getMessage());
            return ResponseFormat.failure(e.getMessage());
        }
        return ResponseFormat.ok("评价成功");
    }

}
